from sqlalchemy import Column, Integer, String, SmallInteger
from app.models.base import Base
from app.libs.enums import PendingStatus


class Drift(Base):
    """
        一次具体的交易信息
    """
    id = Column(Integer, primary_key=True)

    # 邮寄信息
    recipient_name = Column(String(20), nullable=False, comment='收件人姓名')
    address = Column(String(100), nullable=False, comment='收件人地址')
    message = Column(String(200), comment='留言')
    mobile = Column(String(20), nullable=False, comment='收件人手机号码')

    # 书籍信息
    isbn = Column(String(13), comment='书籍isbn编号')
    book_title = Column(String(50), comment='书籍名称')
    book_author = Column(String(30), comment='书籍作者')
    book_img = Column(String(50), comment='书籍图片')

    # 请求者信息
    requester_id = Column(Integer, comment='书籍请求用户id')
    requester_nickname = Column(String(20), comment='书籍请求者昵称')
    # 十一月

    # 赠送者信息
    gifter_id = Column(Integer, comment='书籍赠送用户id')
    gifter_nickname = Column(String(20), comment='书籍赠送用户昵称')
    gift_id = Column(Integer, comment='书籍赠送信息id')

    _pending = Column('pending', SmallInteger, default=1, comment='交易状态')

    @property
    def pending(self):
        return PendingStatus(self._pending)

    @pending.setter
    def pending(self, status):
        self._pending = status.value
